*************************
clear all
set more off
capture log close
set logtype text
cd t:\vega\kilian_vega
set memory 600m
**************************
log using test3, replace
log close

use wti_clean
sort date
save wti_clean, replace

*use retail_gas_daily_clean
*sort date
*save retail_gas_daily_clean, replace


use mms_all_final2, clear
sort date

merge date using wti_clean
*merge date using retail_gas_daily_clean
sort date
 
*GDP Advanced, GDP Preliminary, GDP Final, Unemployment Rate, Nonfarm Payroll, Retail Sales, Industrial Production, Capacity Utilization, Personal Income, Consumer Credit, Personal Consumption Expenditures, New Home Sales, Durable Goods Orders, Construnction Spending, Factory Orders, Business Inventories, Government Budget Deficit, Trade Balance, PPI, Core PPI, CPI, Core CPI, Consumer Confidence Index (Board), Consumer Confidence (U. Mich.), NAPM Index, Housing Starts, Index of Leading Indicators, Target Rate Surprises, Initial Claims
foreach num of numlist 26 27 28 1 7 9 11 10 19 21 17 18 3 13 15 12 20 6 8 34 2 33 71 72 14 16 4 5 32 25 {

*This deals with the problem of missing price change data on a given day; it drops the announcement down to the next day.
replace surs`num'=surs`num'[_n-1] if surs`num' ==. & wti[_n-1] ==. & wti !=. & date-date[_n-1]<=3

}

*After I drop down the announcements, I get rid of the days when no price change occurs.
drop if wti==.

*Now I am turning all the missing values into zero to run the regression:
foreach num of numlist 26 27 28 1 7 9 11 10 19 21 17 18 3 13 15 12 20 6 8 34 2 33 71 72 14 16 4 5 32 25 {

replace surs`num'=0 if surs`num'==.

}

sort date
drop price_ch
gen price_ch=100*(log(wti[_n+20])-log(wti[_n-1]))

gen time=_n
tsset time

reg price_ch surs26 surs27 surs28 surs1 surs7 surs9 surs11 surs10 surs19 surs21 surs17 surs18 surs3 surs13 surs15 surs12 surs20 surs6 surs8 surs34 surs2 surs33 surs71 surs72 surs14 surs16 surs4 surs5 surs32 surs25

global dep=e(N)-e(df_r)
global adj_r2=round(e(r2)*100,0.01)
global obs=e(N)
global depname=e(depvar)
newey price_ch surs26 surs27 surs28 surs1 surs7 surs9 surs11 surs10 surs19 surs21 surs17 surs18 surs3 surs13 surs15 surs12 surs20 surs6 surs8 surs34 surs2 surs33 surs71 surs72 surs14 surs16 surs4 surs5 surs32 surs25, lag(20)

do record.chris.one_tail.do
*test surs26=surs27=surs28=-surs1=surs7=surs9=surs11=surs10=surs19=surs21=-surs25=0
*test surs26=surs27=surs28=-surs1=surs7=surs9=surs11=surs10=surs19=surs21=-surs25=surs17=surs18=surs3=surs13=surs15=-surs12=surs20=surs6=0
*test surs8=surs34=surs2=surs33=0
*test surs71=surs72=surs14=surs16=surs4=surs5=0

test surs26+surs27+surs28-surs1+surs7+surs9+surs11+surs10+surs19+surs21-surs25=0
test surs26+surs27+surs28-surs1+surs7+surs9+surs11+surs10+surs19+surs21-surs25+surs17+surs18+surs3+surs13+surs15-surs12+surs20+surs6=0
test surs8+surs34+surs2+surs33=0
*test surs34+surs2+surs33=0

test surs71+surs72+surs14+surs16+surs4+surs5=0


keep surs26 surs27 surs28 surs1 surs7 surs9 surs11 surs10 surs19 surs21 surs17 surs18 surs3 surs13 surs15 surs12 surs20 surs6 surs8 surs34 surs2 surs33 surs71 surs72 surs14 surs16 surs4 surs5 surs32 surs25 price_ch
order surs26 surs27 surs28 surs1 surs7 surs9 surs11 surs10 surs19 surs21 surs17 surs18 surs3 surs13 surs15 surs12 surs20 surs6 surs8 surs34 surs2 surs33 surs71 surs72 surs14 surs16 surs4 surs5 surs32 surs25 price_ch
drop if price_ch==.
save wti_monthly, replace




